package com.lmr.boot.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class RedisUrlCount implements HandlerInterceptor {
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        stringRedisTemplate.opsForValue().increment(requestURI);
       /* ValueOperations<String, String> operations = stringRedisTemplate.opsForValue();
        String requestURI1 = operations.get("requestURI");
        System.out.println(requestURI+":"+requestURI1);*/
        return true;
    }
}
